// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init({
  env: "test4-ht5oe"
})
const db=cloud.database();
const _ = db.command
// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  try {

    if(event.tip=="user"){
      return await cloud.database().collection('SidelineData').where({
        SidelineID:event.SID
      }).update({
        data:{
          IsServiceable:false,
          SidelineNum:_.inc(1),
        }
        })
    }else{
    return await cloud.database().collection('SidelineData').where({
      SidelineID:event.SID
    }).update({
      data:{
        SidelineName:event.SName,
        SidelineGrade:event.SGrade,
        SidelineImage:event.SImage,
        SidelineBriefIntro:event.SBriefIntro,
        SidelinePrice:event.SPrice,
        IsServiceable:event.SIsService,
        SidelineNum:Number(event.SNum),
        SidelineDetailIntro:event.SDetailIntro
      }
      })
    }
  } catch (e) {
    console.error("ERROR",e)
  }
}